package frontend.pages.admin.occupation;

import backend.model.admin.Occupation;
import backend.service.admin.OccupationService;
import frontend.core.TimeTrackingWebApplication;
import frontend.model.admin.OccupationUIModel;
import frontend.pages.admin.base.AbstractManagingPage;
import org.apache.wicket.markup.html.panel.Panel;
import org.wicketstuff.annotation.mount.MountPath;

import java.util.List;

@MountPath("occupation")
public class OccupationManagingPage extends AbstractManagingPage<Occupation> {

	public OccupationManagingPage() {
		super("pages.admin.occupation.title", "contextualHelp.admin.occupation.text");
	}

    @Override
    protected String getAddPanelTitleKey() {
        return "pages.admin.occupation.add.title";
    }

    @Override
    protected String getEditPanelTitleKey() {
        return "pages.admin.occupation.edit.title";
    }

    @Override
    protected String getNoSelectionMessageKey() {
        return "pages.admin.occupation.edit.noSelection";
    }

    @Override
    protected Panel getAddPanel(String panelId) {
        return new OccupationPanel(panelId, getPageParameters(), new OccupationUIModel());
    }

    @Override
    protected Panel getEditPanel(String panelId, Occupation occupation) {
        getPageParameters().clearNamed();
        return new OccupationPanel(panelId, null, new OccupationUIModel(occupation));
    }

    @Override
    public List<Occupation> loadAvailableEntities() {
        OccupationService occupationService = TimeTrackingWebApplication.getService(OccupationService.class);
        return occupationService.findAllOccupations();
    }
}
